package com.vichat.user.service;

import com.vichat.common.enums.RecordType;
import com.vichat.common.exception.ViChatException;
import com.vichat.common.vo.PageFilter;
import com.vichat.common.vo.SysMsg;
import com.vichat.user.entity.*;
import com.vichat.user.vo.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by ranjx on 2017/10/13.
 */
public interface IUserService {


    /**
     * 获取平台所有企业
     *
     * @return
     */
    public List<UserParty> getUserPartys();

    /**
     * 获取企业信息
     *
     * @param partyId
     * @return
     */
    public UserParty getUserPartyById(long partyId);

    /**
     * 查询组织
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserOrg> queryUserOrgs(UserOrg queryBean, PageFilter pf);


    /**
     * 查询组织数量
     *
     * @param queryBean
     * @return
     */
    public Long countUserOrgs(UserOrg queryBean) throws Exception;


    /**
     * 根据组织编号查询组织
     *
     * @param orgCode
     * @return
     */
    public List<UserOrg> queryUserOrgsByOrgCode(String orgCode);

    /**
     * 根据组织编号查询组织,附加过滤
     *
     * @param orgCode
     * @return
     */
    public List<UserOrg> queryUserOrgsByOrgCodeC(String orgCode, String orgCodeName);

    /**
     * 根据组织ID获取组织信息
     *
     * @param orgId
     * @return
     */
    public UserOrg queryUserOrgByOrgId(long orgId);


    /**
     * 根据上级组织下查询组织部门
     *
     * @param parentId
     * @return
     */
    public List<UserOrg> queryUserOrgsByParentId(long parentId);

    /**
     * 添加或者修改组织
     *
     * @param org
     */
    public UserOrg saveUserOrg(UserOrg org) throws Exception;


    /**
     * 删除组织
     *
     * @param orgId
     */
    public void delUserOrg(long partyId, long orgId) throws ViChatException;


    /**
     * 查询用户信息
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserBasic> queryUserBasics(UserBasic queryBean, PageFilter pf,boolean isPrecise) throws Exception;


    /**
     * 查询用户数量
     *
     * @param queryBean
     * @return
     */
    public Long countUserBasics(UserBasic queryBean,boolean isPrecise) throws Exception;

    /**
     * 查询用户信息
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserBasicVO> queryUserBasicsBySql(UserBasic queryBean, PageFilter pf) throws Exception;

    /**
     * 查询用户信息
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserBasicVO> queryUserBasicsBatch(UserBasic queryBean, PageFilter pf) throws Exception;


    /**
     * 查询用户数量
     *
     * @param queryBean
     * @return
     */
    public BigInteger countUserBasicsBySql(UserBasic queryBean) throws Exception;


    /**
     * 根据uid获取用户信息
     *
     * @param uid
     * @return
     */
    public UserBasic getUserBasicByUid(long uid);

    /**
     * 根据uid获取用户信息
     *
     * @param uid
     * @return
     */
    public UserBasic queryUserBasicByUid(long uid);


    /**
     * 保存或者修改用户信息
     *
     * @param user
     * @return user主键
     */
    public UserBasic saveUserBasic(UserBasic user) throws Exception;

    public void updateUserBasicVersion(long uid);
    public void updateUserOrgVersion(long uid);
    public void updateUserBasicVersionByPartyId(long partyId);


    /**
     * 删除用户信息
     *
     * @param uid
     */
    public void delUserBasic(long partyId, long uid) throws Exception;


    /**
     * 企业注册
     *
     * @param party
     * @param company
     * @param user
     * @throws Exception
     */
    public void registerPartyCompany(UserParty party, UserPartyCompany company, UserBasic user) throws Exception;


    /**
     * 根据部门名称查询部门
     *
     * @param name
     * @return
     */
    public List<UserOrg> getUserOrgByName(String name, Long orgId, Long partyId);


    /**
     * 修改密码
     *
     * @param user
     * @throws Exception
     */
    public void updUserPwd(UserBasic user) throws Exception;


    /**
     * 查询上级组织
     *
     * @param orgCode
     * @param orgCodeName
     * @return
     */
    public List<UserOrg> queryParUserOrgsByOrgCodeC(String orgCode, String orgCodeName, long partyId);

    /**
     * 根据uid查询用户信息
     *
     * @param partyId
     * @param uid
     * @return
     */
    public UserBasic getUserBasicByUid(long partyId, long uid);


    /**
     * 获取人员总览
     *
     * @return
     */
    public UserOnlineVO getUserOnlineView(UserBasic queryBean);


    /**
     * 查询组织
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserOrg> queryUserOrgsApi(UserOrg queryBean, PageFilter pf);

    /**
     * 查询组织数量
     *
     * @param queryBean
     * @return
     */
    public Long countUserOrgsApi(UserOrg queryBean) throws Exception;

    /**
     * 查询用户信息Api接口
     *
     * @param queryBean
     * @param pf
     * @return
     */
    public List<UserVO> queryApiUserBasics(UserBasic queryBean, PageFilter pf) throws Exception;

    /**
     * 修改用户角色权限
     *
     * @param uid
     * @param roid
     */
    public void saveUserSecRoleRel(Long uid, Long roid);

    public List<UserBasic> getOnlineUsers(UserBasic queryBean);

    public void updateLocationFlag(Long uid, Long flag, Long interval);

    public void saveUserOrg(UserBasic userFDB, Long orgId) throws ViChatException;


    /**
     * 注册企业，无须管理员账号，接口提供给阿里通信平台
     *
     * @param companyName
     * @param flag
     * @return
     */
    public CompanyVO registerCompanyNoAdmin(String companyName, String flag, long appId);


    /**
     * 延期续费接口
     *
     * @param partyId
     * @param uid
     * @param expiredDate
     * @return
     * @throws Exception
     */
    public UserBasic activateUser(long partyId, long uid, Date expiredDate) throws Exception;

    /**
     * 根据partyId获取默认组织编号
     *
     * @param partyId
     * @return
     */
    public UserOrg getRootOrgByPartyId(long partyId);

    public UserBasic getUserBasicByTerminal(String terminal);

    public List<UserBasic> queryUserBasicsByRoid(long roid);

    /**
     * 保存操作日志
     *
     * @param user
     * @param type
     * @param opedUid
     * @param opedUserName
     * @param opedInfo
     * @param remark
     * @throws Exception
     */
    public void saveSysBusiRecord(UserBasic user, RecordType type, long opedUid, String opedUserName, String opedInfo, String remark);


    /**
     * 根据条件查询角色信息
     *
     * @param uid
     * @return
     */
    public List<SecRole> querySecRoleByUid(Long uid);


    public UserPartyCompany getUserPartyCompanyByPartyId(Long partyId);

    public List<UserBasic> getUserBasicsByOrgId(Long orgId);

    public Map<String, List<UserBasic>> batchCreateUser(List<UserBasic> users);

    public boolean isIccidExist(String iccid);

    public boolean isImeiExist(String imei);

    public Boolean isTerminalExist(String terminal);

    public void checkIsAccountExist(String terminal) throws ViChatException;

    /**
     * 根据组织编号orgId查询组织
     *
     * @return
     */
    public UserOrg queryUserOrgByOrgId(long partyId, long orgId);

    public List<UserOrg> queryUserOrgByOrgName(long partyId, String orgName);

    public UserBasic getUserBasicByPartyId(long partyId, long userType);

    public void updateOnlineState(Long uid, Integer displayStateOffline);

    public List<UserCompanyVO> queryExpiringUser(int day, UserCompanyVO queryBean, PageFilter pageFilter) throws Exception;

    public BigInteger countExpiringUser(int day, UserCompanyVO queryBean) throws Exception;

    public BigInteger countExpiredUser(UserPartyCompany queryBean) throws Exception;

    public List<UserCompanyVO> queryExpiredUser(UserPartyCompany queryBean, PageFilter pageFilter) throws Exception;

    /**
     * 获取当前平台有效人数
     */
    public long countEffetiveUser();

    public long countEffetiveUserByPartyId(long partyId);

    public long countEffetiveTermianlUser();

    public long countEffetiveDispatcherUser();

    public long countEffetiveUserExceptPartyAdminByPartyId(long partyId);
    /**
     * 停用用户
     *
     * @param uid
     */
    public void stopUserBasic(long partyId, long uid) throws Exception;
    public void startUserBasic(long partyId, long uid) throws Exception;

    public void deleteCompany(long partyId);

    public void excuteTaskSql(String sql)throws Exception;

    public List<RechargeRecord> queryRechargeRecord(RechargeRecord rechargeRecord, PageFilter pageFilter) throws Exception;

    public long countRechargeRecord(RechargeRecord rechargeRecord) throws Exception;

    public void setRechargeRecordRemark(long logId, String remark) throws ViChatException;

    /**
     * 查询用户信息
     *
     * @param queryBean
     * @return
     */
    public List<UserBasicVO> queryUserBasicToRoom(UserBasic queryBean,PageFilter pageFilter, String userType) throws Exception;
    public BigInteger countUserBasicToRoom(UserBasic queryBean) throws Exception;

    public void updateExpiredDate(UserBasic sessionUser, UserBasic userFDB, Integer monthNumber) throws ViChatException;

    public List<UserBasic> queryExpiredUser();

    public List<UserBasic> queryUserByFuncDesc(String[] funcDesc, long pOrgId);


    public List<SysBusiRecord> querySysBusiRecord(SysBusiRecord queryBean, PageFilter pageFilter);

    public long countSysBusiRecord(SysBusiRecord queryBean);

    public List<UserBasic> getUserBasicsByRole(long roleId,Long orgId ,String orgCode);

}
